备份方法: 参见 http://www.jb51.net/article/40285.htm
整库备份:
mongodump -h dbhost -d dbname -o dbdirectory
整库恢复:
mongorestore -h dbhost -d dbname –directoryperdb dbdirectory
单表备份:
mongoexport -h dbhost -d dbname -c collectionname -f collectionKey -o dbdirectory
单表恢复
mongoimport -d my_mongodb -c user user.dat
恢复过程中报错:
mongoimport -d popstar -c mails mails
2015-11-02T10:05:25.228+0100 connected to: localhost
2015-11-02T10:05:25.735+0100 error inserting documents: lost connection to server
2015-11-02T10:05:25.735+0100 Failed: lost connection to server
2015-11-02T10:05:25.735+0100 imported 0 documents
guess the problem is about performance, any way you can solved used:
you can use mongoimport option -j. Try increment if not work with 4. i.e, 4,8,16, depend of the number of core you have in your cpu.
mongoimport –help
-j, –numInsertionWorkers= number of insert operations to run concurrently (defaults to 1)
完美解决语句:
mongoimport -d popstar -c mails mails -j 10